package com.milk.controller.admin;

import com.milk.result.Result;
import com.milk.service.ReportService;
import com.milk.vo.OrderReportVO;
import com.milk.vo.SalesTop10ReportVO;
import com.milk.vo.TurnoverReportVO;
import com.milk.vo.UserReportVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@RequestMapping("/admin/report")
@Slf4j
@CrossOrigin
public class ReportController {

    @Autowired
    private ReportService reportService;

    /**
     * 营业额统计接口
     * @return
     */
    @GetMapping("/turnoverStatistics")
    @ApiOperation("营业额统计接口")
    public Result<TurnoverReportVO> turnoverStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                                       @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end) {
        log.info("查询的日期：{}-{}",begin,end);
        String key = "日期" + begin + "-" + end;

        TurnoverReportVO vo = reportService.turnoverStatistics(begin, end);
        return Result.success(vo);
    }

    /**
     * 用户统计
     * @return
     */
    @GetMapping("/userStatistics")
    @ApiOperation("用户统计")
    public Result<UserReportVO> userReport(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                           @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        log.info("用户统计:{},{}",begin,end);
        UserReportVO userReportVO = reportService.userStaistics(begin,end);
        return Result.success(userReportVO);
    }

    /**
     * 订单统计
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/ordersStatistics")
    @ApiOperation("订单统计")
    public Result<OrderReportVO> ordersStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                                  @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {

        log.info("订单统计:{},{}", begin, end);
        OrderReportVO vo = reportService.ordersStatistics(begin, end);
        return Result.success(vo);
    }

    /**
     * 查询销量排名top10
     * @return
     */
    @GetMapping("/top10")
    @ApiOperation("查询销量排名top10")
    public Result<SalesTop10ReportVO> top10Statistics(){

        SalesTop10ReportVO vo= reportService.getTop10();

        return Result.success(vo);
    }
}

